package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.ParamTemplateService;
import com.yexiao.cofe.resolver.IRequestParam;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lkl
 * @since 2025/4/1
 */
@RestController
@RequestMapping("/param/template")
public class ParamTemplateController {
    
    @Resource
    private ParamTemplateService paramTemplateService;

    @PostMapping("/add")
    public ResponseData addParamValue(@RequestBody JSONObject param, @IRequestToken String token) {
        paramTemplateService.addTemplate(param);
        return ResponseData.success();
    }

    @GetMapping("/del")
    public ResponseData deleteParamValue(@RequestParam Integer templateId, @IRequestToken String token) {
        paramTemplateService.delTemplate(templateId);
        return ResponseData.success();
    }

    @PostMapping("/modify")
    public ResponseData modify(@RequestBody JSONObject param, @IRequestToken String token) {
        paramTemplateService.modifyTemplate(param);
        return ResponseData.success();
    }

    @PostMapping("/bind")
    public ResponseData bindParamValue(@RequestBody JSONObject param, @IRequestToken String token) {
        paramTemplateService.bindParamValue(param);
        return ResponseData.success();
    }

    @GetMapping("/detail")
    public ResponseData getTemplateDetail(@RequestParam Integer templateId, @IRequestToken String token) {

        return ResponseData.success(paramTemplateService.getTemplateDetail(templateId));
    }

    @GetMapping("/getStoreTemplate")
    public ResponseData getStoreTemplate(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(paramTemplateService.getStoreTemplate(param));
    }
}
